<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::domain('iot.'.config('app.domain'))->group(function (){
    // 注册包与dat包
    Route::post('iyineng/IOTSerlvet', 'ReceiveController@dat');
    Route::get('iyineng/IOTSerlvet', 'ReceiveController@dat');
    // 心跳包
    Route::post('iyineng/exeSerlvet', 'ReceiveController@tck');
    Route::get('iyineng/exeSerlvet', 'ReceiveController@tck');
});


Route::get('/tree', '\App\Admin\Controllers\AreasController@tree');
Route::post('/treeData', '\App\Admin\Controllers\AreasController@treeData');
Route::get('/positions', '\App\Admin\Controllers\AreasController@positions');
Route::get('/showType/{type}', '\App\Admin\Controllers\AreasController@showType');
Route::get('/map', '\App\Admin\Controllers\AreasController@map');

Route::get('/tree/data/{code}', function () {
    header('Access-Control-Allow-Origin: *');
    $area = \App\Area::with('products')->get()->map(function ($area) {
        return [
                'name' => $area->name,
                'code' => $area->id,
                'child' => $area->products->map(function ($product) {
                    return ['child' => [], 'name' => $product->name, 'code' => $product->id];
                }),
            ];
    });
    return $area;
});
